package com.sjsu.web.poller;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sjsu.aws.ephermeralnode.DoubleBarrierEphemeralWatcher;
import com.sjsu.aws.ephermeralnode.GroupMemShipEphemeralWatcher;

/**
 * Servlet implementation class DataPoller
 */
public class DataPoller extends HttpServlet {
	private static final long	serialVersionUID	= 1L;
	
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DataPoller() {
		super();
	}
	
	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		
		long pollingPeriod = 10000;
		try {
			System.out.println(String.format(
			        "Start Polling with polling period=%s", pollingPeriod));
			GroupMemShipEphemeralWatcher.startPolling(pollingPeriod);
			DoubleBarrierEphemeralWatcher.startPolling(pollingPeriod);
		} catch (Exception e) {
			System.out.println("Could not start Polling, " + e.getMessage());
			e.printStackTrace();
		}
	}
	
	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
	}
	
	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request,
	        HttpServletResponse response) throws ServletException, IOException {
		
	}
	
}
